package interview.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: zhangrongqing
 * @Date: 2020/5/22 8:53
 */
public class PrintAandB {

    public void printA() throws InterruptedException {

        synchronized (this){
            this.wait();
            System.out.println("A");
        }
    }

    public void printB() throws InterruptedException {
        synchronized (this){
            System.out.println("B");
            this.notify();
        }
    }


    public static void main(String[] args) {

        PrintAandB task = new PrintAandB();
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for(int i = 0;i < 10;i++){
            executorService.submit(()-> {
                try {
                    task.printA();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }

        ExecutorService executorService2 = Executors.newFixedThreadPool(10);
        for(int i = 0;i < 10;i++){
            executorService2.submit(()-> {
                try {
                    task.printB();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }

        executorService.shutdown();
        executorService2.shutdown();
    }
}
